package com.comtrade.sharedpreferences;

import android.content.Context;
import android.content.SharedPreferences;

public class DomesticSharedPreferences {
	
	private SharedPreferences sharedPreferences;
	
	public void savePreferences(Context activity, String key, String value) {
		
		sharedPreferences = activity.getSharedPreferences(key, Context.MODE_PRIVATE);
			        SharedPreferences.Editor editor = sharedPreferences.edit();
			        editor.putString(key, value);
			        editor.clear();
			        editor.commit();
			        
			    }
	
	public String getPreferences(Context activity, String key) {
			
		sharedPreferences = activity.getSharedPreferences(key, Context.MODE_PRIVATE);
	        String s = sharedPreferences.getString(key, "");
	        return s;
	    }
	
	public String UzmiSamoIP(String url)
	{
		//podrazumeva se da je url tipa: http://IP:port/ils			
        if (url!=""){
        	String[] niz1 = url.split("/");
        	String[] niz2 = niz1[2].split(":");          
        	return niz2[0];		
        }
        return null;
	}

	
	public String OdIPuURL(String ip)
	{
		String url = "http://"+ip+":8080/ils";
		return url;
		
	}
}
